<%--
  Created by IntelliJ IDEA.
  User: 女孩
  Date: 2022/8/28
  Time: 19:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="./static/layui/css/layui.css" media="all">
    <script src="./static/layui/layui.js"></script>
    <style>
        *{
            margin: 0 auto;
        }
        .xh1{
            width: 100%;
            height: 740px;
            background-color: #7ab6b6;
            box-sizing: border-box;
            padding-top: 210px;
            padding-left: 600px;
        }
        .xh2{
            width: 350px;
            height: 380px;
            text-align: center;
            padding-top: 15px;
            background-color: white;
            box-shadow: 10px 6px  #a09077;

        }
        .a{
            margin-left: -10px;
            position: absolute;
            line-height: 50px;
        }
    </style>
</head>
<body>
<div class="xh1">
    <div class="xh2">
        <h2 style="margin-bottom: 30px;">登录页面</h2>
        <form class="layui-form a" action="">
            <div class="layui-form-item "> <label class="layui-form-label">账号</label>
                <div class="layui-input-block">
                    <input type="text" name="title" id="username" lay-verify="title" autocomplete="off" placeholder="请输入账号" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item"> <label class="layui-form-label">密码</label>
                <div class="layui-input-block">
                    <input type="text" id="password" name="password" lay-verify="required" lay-reqtext="用户名是必填项，岂能为空？" placeholder="请输入密码" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn " id="login"  lay-submit="" lay-filter="demo1">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
            <button type="reset" class="layui-btn layui-btn-primary">注册</button>
        </form>
    </div>
</div>
</body>



<script>
    layui.use(['table', 'form', 'jquery','upload'], function () {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        form.on('submit(demo1)', function(data){
            let username = $("#username").val();
            let password = $("#password").val();
            if (username == '') {
                layer.msg('登录账号不能为空');
                return false;
            }
            if (password == '') {
                layer.msg('密码不能为空');
                return false;
            }
            //发送ajax请求
            $.ajax({
                url: "user/login.do",
                data: {"username": username, "password": password},
                //响应的数据类型
                dataType: "JSON",
                type: "POST",
                //异步请求
                async: true,
                //成功的回调
                success: function (data) {
                    //登录成功
                    if (data.code == 0) {
                        window.location.href = "views/show.jsp"
                    } else {
                        //登录失败
                        console.log(data.msg);
                        // window.location.href = "de.jsp"
                        layer.msg(data.msg)
                    }
                }
            })
            return false;
        })
    })

</script>
</html>

